package com.desk.api.constant;

import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum LearnStatus {
  LEARNED(0, "学习结束"),
  LEARN_START(1, "学习开始"),
  LEAR_TIME_OUT(2, "学习暂停"),
  LEARN_CONTINUE(3, "学习继续");

  @EnumValue private final Integer code;
  @JsonValue private final String desc;

  public static Opt<LearnStatus> getByCode(Integer code) {
    for (LearnStatus status : LearnStatus.values()) {
      if (status.getCode().equals(code)) {
        return Opt.ofNullable(status);
      }
    }
    return Opt.empty();
  }
}
